package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.AnnualWorkDays;
import com.ruoyi.business.service.IAnnualWorkDaysService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 全年出班天数Controller
 *
 * @author ruoyi
 * @date 2024-11-17
 */
@Api(tags = "全年出班天数管理",value = "全年出班天数管理", description = "全年出班天数管理，包括查询、新增、修改、删除等功能")
@RestController
@RequestMapping("/business/days")
public class AnnualWorkDaysController extends BaseController
{
    @Autowired
    private IAnnualWorkDaysService annualWorkDaysService;

    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:user:import')")
    @PostMapping("/importData")
    @ApiOperation(value = "导入全年出班天数数据", notes = "支持更新已有数据")
    public AjaxResult importData(
            @ApiParam(value = "上传的Excel文件", required = true) MultipartFile file,
            @ApiParam(value = "是否更新已有数据", required = true) boolean updateSupport) throws Exception
    {
        ExcelUtil<AnnualWorkDays> util = new ExcelUtil<AnnualWorkDays>(AnnualWorkDays.class);

        List<AnnualWorkDays> userList = util.importExcel("全年出班天数数据",file.getInputStream(),1);
        String operName = getUsername();
        String message = annualWorkDaysService.importData(userList, updateSupport, operName);
        return success(message);
    }

    @PostMapping("/importTemplate")
    @ApiOperation(value = "导出全年出班天数数据模板", notes = "提供Excel模板用于导入")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<AnnualWorkDays> util = new ExcelUtil<AnnualWorkDays>(AnnualWorkDays.class);
        util.importTemplateExcel(response, "全年出班天数数据","全年出班天数数据");
    }

    /**
     * 查询全年出班天数列表
     */
    @PreAuthorize("@ss.hasPermi('business:days:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询全年出班天数列表", notes = "分页查询全年出班天数列表")
    public TableDataInfo list(AnnualWorkDays annualWorkDays)
    {
        startPage();
        List<AnnualWorkDays> list = annualWorkDaysService.selectAnnualWorkDaysList(annualWorkDays);
        return getDataTable(list);
    }

    /**
     * 导出全年出班天数列表
     */
    @PreAuthorize("@ss.hasPermi('business:days:export')")
    @Log(title = "全年出班天数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出全年出班天数列表", notes = "将查询到的全年出班天数数据导出为Excel文件")
    public void export(HttpServletResponse response, AnnualWorkDays annualWorkDays)
    {
        List<AnnualWorkDays> list = annualWorkDaysService.selectAnnualWorkDaysList(annualWorkDays);
        ExcelUtil<AnnualWorkDays> util = new ExcelUtil<AnnualWorkDays>(AnnualWorkDays.class);
        util.exportExcel(response, list, "全年出班天数数据");
    }

    /**
     * 获取全年出班天数详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:days:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取全年出班天数详细信息", notes = "根据ID查询全年出班天数详细信息")
    public AjaxResult getInfo(@ApiParam(value = "全年出班天数ID", required = true) @PathVariable("id") Long id)
    {
        return success(annualWorkDaysService.selectAnnualWorkDaysById(id));
    }

    /**
     * 新增全年出班天数
     */
    @PreAuthorize("@ss.hasPermi('business:days:add')")
    @Log(title = "全年出班天数", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增全年出班天数", notes = "添加新的全年出班天数记录")
    public AjaxResult add(@ApiParam(value = "全年出班天数对象", required = true) @RequestBody AnnualWorkDays annualWorkDays)
    {
        return toAjax(annualWorkDaysService.insertAnnualWorkDays(annualWorkDays));
    }

    /**
     * 修改全年出班天数
     */
    @PreAuthorize("@ss.hasPermi('business:days:edit')")
    @Log(title = "全年出班天数", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改全年出班天数", notes = "更新现有的全年出班天数记录")
    public AjaxResult edit(@ApiParam(value = "全年出班天数对象", required = true) @RequestBody AnnualWorkDays annualWorkDays)
    {
        return toAjax(annualWorkDaysService.updateAnnualWorkDays(annualWorkDays));
    }

    /**
     * 删除全年出班天数
     */
    @PreAuthorize("@ss.hasPermi('business:days:remove')")
    @Log(title = "全年出班天数", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除全年出班天数", notes = "根据ID删除全年出班天数记录")
    public AjaxResult remove(@ApiParam(value = "全年出班天数ID数组", required = true) @PathVariable Long[] ids)
    {
        return toAjax(annualWorkDaysService.deleteAnnualWorkDaysByIds(ids));
    }
}
